﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;

namespace MainApp
{
    public partial class FrmGetName : DevExpress.XtraEditors.XtraForm
    {
        public FrmGetName()
        {
            InitializeComponent();
        }

        public FrmGetName(string oldName)
            : this()
        {
            txtInput.Text = oldName;
            btnOK.Enabled = true;
            //txtInput.Validating += new CancelEventHandler(txtInput_Validating);
            //txtInput.Validated += new EventHandler(txtInput_Validated);
            txtInput.EditValueChanged += new EventHandler(txtInput_EditValueChanged);
        }

        void txtInput_EditValueChanged(object sender, EventArgs e)
        {
            if (txtInput.Text.Trim().Length == 0)
            {
                btnOK.Enabled = false;
            }
            else
            {
                btnOK.Enabled = true;
            }
        }

        //void txtInput_Validated(object sender, EventArgs e)
        //{
        //    btnOK.Enabled = true;
        //    btnOK.Focus();
        //}

        //void txtInput_Validating(object sender, CancelEventArgs e)
        //{
        //    e.Cancel = (txtInput.Text.Trim().Length == 0);                        
        //}

        private void btnOK_Click(object sender, EventArgs e)
        {
            DialogResult = System.Windows.Forms.DialogResult.OK;
            this.Close();
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            DialogResult = System.Windows.Forms.DialogResult.Cancel;
            this.Close();
        }

        public string GetName()
        {
            return txtInput.Text.Trim();
        }

    }
}